<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@page import="java.net.URLDecoder"%>
<%@ page import="com.sz.ticket.dao.ITicketDAO" %>
<%@ page import="com.sz.common.SZUtility" %>
<%@page import="com.sz.business.dao.IBusinessDAO"%>

<%
//参照viewTicket.jsp 
//如有更给，要考虑viewTicket.jsp 是否要改

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";


String style1 = "width: 80px;text-align:right;font-size: 12px;";

//String input_text = "width: 220px; background:#FFFFFF";
String input_text_gray = "width: 240px; background:#C0C0C0";

String title = request.getParameter("title");
if(title != null) {
	title = URLDecoder.decode(title, "UTF-8");
}

//模式 	mode_edit 或  mode_confirm
String mode = request.getParameter("mode");
if(mode==null || mode.equals("")) {
	mode = "mode_edit";
}

String cur_version = request.getParameter("cur_version"); //当前版本

String final_callback = request.getParameter("final_callback");
if(final_callback == null) final_callback = "";

ServletContext servletContext = request.getSession().getServletContext(); 
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
ITicketDAO ticket = (ITicketDAO) context.getBean("TicketDAO");
IBusinessDAO business = (IBusinessDAO) context.getBean("BusinessDAO");

Map<Object, Object> param = new HashMap<Object, Object>();
String ticket_id = request.getParameter("ticket_id");
param.put("TICKET_ID", ticket_id);
List list = ticket.queryTicket(param);
String bExist = "1";	//订单是否存在的标志
Map map = new HashMap();
if(list.size() > 0) {
	map = (Map)list.get(0);
	bExist = "1";
} else {
	bExist = "0";
}

String cust_tel = SZUtility.toString(map.get("CUST_TEL"));
String cust_name = SZUtility.toString(map.get("CUST_NAME"));
String business_id = SZUtility.toString(map.get("BUSINESS_ID"));
String demand_time_str = SZUtility.toString(map.get("DEMAND_TIME_STR"));
String demand_num = SZUtility.toString(map.get("DEMAND_NUM"));
String demand_addition = SZUtility.toString(map.get("DEMAND_ADDITION"));
String staff_num = SZUtility.toString(map.get("STAFF_NUM"));
String create_manager_name = SZUtility.toString(map.get("CREATE_MANAGER_NAME"));
String create_time_str = SZUtility.toString(map.get("CREATE_TIME_STR"));
String lock_time_str = SZUtility.toString(map.get("LOCK_TIME_STR"));
String lock_manager = SZUtility.toString(map.get("LOCK_MANAGER"));
String lock_manager_name = SZUtility.toString(map.get("LOCK_MANAGER_NAME"));
String custom_change = SZUtility.toString(map.get("CUSTOM_CHANGE"));
String business_response = SZUtility.toString(map.get("BUSINESS_RESPONSE"));
String version_str = SZUtility.toString(map.get("VERSION_STR"));

String business_name = SZUtility.toString(map.get("BUSINESS_NAME"));
String business_regionname = SZUtility.toString(map.get("BUSINESS_REGIONNAME"));
String business_address = SZUtility.toString(map.get("BUSINESS_ADDRESS"));
String business_tel = SZUtility.toString(map.get("BUSINESS_TEL"));
String low_fee = SZUtility.toString(map.get("LOW_FEE"));
String landmark = SZUtility.toString(map.get("LANDMARK"));

String card_no = SZUtility.toString(map.get("CARD_NO"));
String position_flag = SZUtility.toString(map.get("POSITION_FLAG"));
String nosmoking_flag = SZUtility.toString(map.get("NOSMOKING_FLAG"));
String window_flag = SZUtility.toString(map.get("WINDOW_FLAG"));
String baby_flag = SZUtility.toString(map.get("BABY_FLAG"));
String wc_flag = SZUtility.toString(map.get("WC_FLAG"));
String notice_flag = SZUtility.toString(map.get("NOTICE_FLAG"));

String business_change = SZUtility.toString(map.get("BUSINESS_CHANGE"));
String discount_descrip = SZUtility.toString(map.get("DISCOUNT_DESCRIP"));
String need_deposit = SZUtility.toString(map.get("NEED_DEPOSIT"));
String contact = SZUtility.toString(map.get("CONTACT"));
String comment_text = SZUtility.toString(map.get("COMMENT_TEXT"));

String demand_time_d = demand_time_str.substring(0,10);
String demand_time_t = demand_time_str.substring(11,16);

String status = SZUtility.toString(map.get("STATUS"));
String status_name = SZUtility.toString(map.get("STATUS_NAME"));

String confirm_b = SZUtility.toString(map.get("CONFIRM_B"));
String confirm_c = SZUtility.toString(map.get("CONFIRM_C"));

String cust_sex = SZUtility.toString(map.get("CUST_SEX"));

String from = "";
String auto_confirm_disabled = "0";
String auto_confirm_tip = "";
if(status.equals("21")) {
	//商家更改，确认
	//此时，需要客户先确认
	if(confirm_c.equals("1") && !confirm_b.equals("1")) { //客户已经确认过了，商家还未确认
		from = "2";
		auto_confirm_tip = "自动客户确认";
		auto_confirm_disabled = "1";
	} else {
  		from = "1"; //客户
  		auto_confirm_tip = "自动商家确认";
  	}
  	
} else {
	//此时，需要商家先确认
	if(confirm_b.equals("1") && !confirm_c.equals("1")) { //商家已经确认过了,客户还未确认
		from = "1";
  		auto_confirm_tip = "自动商家确认";
  		auto_confirm_disabled = "1";		
	} else if(!confirm_b.equals("1") && confirm_c.equals("1")) { //商家未确认，但客户确认了
		from = "2";
		auto_confirm_tip = "自动客户确认";
		auto_confirm_disabled = "1";
	} else {
  		from = "2";
		auto_confirm_tip = "自动客户确认";		
  	}  	
}
if(mode.equals("mode_edit")) {
	//目前认为编辑只能是客户编辑
	from = "1";
	auto_confirm_tip = "自动商家确认";
	auto_confirm_disabled = "0";
}

String position_tip = "";
if(position_flag.equals("0")) {
	position_tip = "不限";
} else if(position_flag.equals("1")) {
	position_tip = "大厅";
} else if(position_flag.equals("2")) {
	position_tip = "包房";
}

String error = "";
String userid = SZUtility.toString(request.getSession().getAttribute("userid"));
if(userid.length() == 0) {
	error = "请重新登陆";
} else { 
	if(mode.equals("mode_confirm")) { //确认模式
		if(lock_manager.equals("")) {
			//空闲的订单 自动锁定
			Map tmp = new HashMap();
			tmp.put("TICKET_ID", ticket_id);
			tmp.put("LOCK_MANAGER", userid);
			tmp.put("MYVERSION", version_str);
			tmp.put("LOCKFLAG", "1");
			error = ticket.lockTicket(tmp);
		} else if(!lock_manager.equals(userid)) {
			error = "该订单已被其他用户预占";
		}		
	}
}

if(error == null) error = ""; //认为null是没有错误
%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<link href="<%= request.getContextPath() %>/css/main.css" rel="stylesheet" type="text/css" />
		<base href="<%=basePath%>" target="_self">
		<title><%=title%></title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="addTicket">
		<meta http-equiv="description" content="<%=title%>" >
	</head>
	
	<body onload="onLoad()">
		<script type="text/javascript" src="js/calendar.js"></script>
		<script type="text/javascript" src="js/utility.js"></script>
		<table width="100%">
		  <tr>
		  	<td colspan="3" class="title0" ><%=title%></td>		  	
	  	  </tr>
	  	</table>

	  	<table id = "business_info" width="100%" border="0" cellpadding="0" cellspacing="0" style="line-height:30px;">
	  		<tr>
	  			<th colspan="6" align="left">&nbsp;商家信息</th>
	  		</tr>
	  		<tr style="display:none">
	  			<td>
	  				<input type="hidden" id="business_id" name="business_id" value="<%=business_id%>"/>
	  			</td>
	  		</tr>
	  		<tr>
	  			<td style="<%=style1%>">商家名称&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="business_name" name="business_name" value="<%=business_name%>"  readonly="readonly" style="<%=input_text_gray%>" >
	  				<input type="button" value="..." onclick="OnChangeBusiness()"/>
	  			</td>
	  			
	  			<td style="<%=style1%>">区域&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="business_regionname" name="business_regionname" value="<%=business_regionname%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  			
	  			<td style="<%=style1%>">地址&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="business_address" name="business_address" value="<%=business_address%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  		</tr>
	  		
	  		<tr>
	  			<td style="<%=style1%>">预订电话&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="business_tel" name="business_tel" value="<%=business_tel%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  			
	  			<td style="<%=style1%>">最低消费&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="low_fee" name="low_fee" value="<%=low_fee%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  			
	  			<td style="<%=style1%>">地标&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="landmark" name="landmark" value="<%=landmark%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  		</tr>	  		
	  
	  
	  	 	<tr>
	  			<th colspan="6" align="left">&nbsp;订单信息</th>
	  		</tr>		  	
  		<tr>
		  	<td style="<%=style1%>">客户电话&nbsp;&nbsp;</td>
		  	<td>
		  		<input type="text" id="cust_tel" name="cust_tel" value="<%=cust_tel%>" readonly="readonly" style="<%=input_text_gray%>" >
		  	</td>
		  	
		  	<td style="<%=style1%>">客户姓名&nbsp;&nbsp;</td>
		  	<td>
		  		<input type="text" id="cust_name" name="cust_name" value="<%=cust_name%>" readonly="readonly" style="<%=input_text_gray%>" >
		  	</td>
		  	
		  	<td style="<%=style1%>">客户性别</td>
		  	<td style="font-size: 12px;">
		  		&nbsp;<input type="radio" id="sex_male" onclick="onClickRadio_sex('sex_male')">男
		  		<input type="radio" id="sex_female" onclick="onClickRadio_sex('sex_female')">女
		  		<input type="radio" id="sex_unknown" onclick="onClickRadio_sex('sex_unknown')">未知
		  	</td>		  				 
	  	</tr>
  		  	
	  	<tr>
	  		<td style="<%=style1%>">预约时间&nbsp;&nbsp;</td>
		  	<td>
		  		<input type="text" id="demand_time_d" name="demand_time_d" style="width: 95px;" value="<%=demand_time_d%>" readonly="readonly" onclick="calendar.show(this)" >
		  		<select id="demand_time_t" name="demand_time_t" style="width: 80px;" >
		  		  <option selected="selected"></option>
		  		  <%
		  		  String value;
		  		  String text;
		  		  
		  		  String value_half;
		  		  String text_half;
		  		  boolean b = false;
		  		  boolean b_half = false;
				  for(int n = 0; n < 24; ++n) {
				   	  String t = String.format("%02d", n);				  
					  value = t + ":" + "00";
					  text = t + "时";
					  
					  value_half = t + ":" + "30";
					  text_half = " " + t + "时" + "30分";
					  					  
					 
					  b = value.equals(demand_time_t);
					  b_half = value_half.equals(demand_time_t);					  					
					 
				  %>
				   <option <%if(b){%> selected="selected" <%}%>
				     value="<%=value%>"><%=text%>
				   </option>
				   <option <%if(b_half){%> selected="selected" <%}%>
				     value="<%=value_half%>"><%=text_half%>
				   </option>
				  <%}%>				   
		  		</select>
		  	</td>
		  		
		  	<td style="<%=style1%>">预约桌数&nbsp;&nbsp;</td>
		  	<td>
		  		<input type="text"  id="demand_num" name="demand_num"  value="<%=demand_num%>" style="<%=input_text_gray%>">
		  	</td>
		  	
		  	<td style="<%=style1%>">用餐人数&nbsp;&nbsp;</td>
		  	<td>
		  		<input type="text" id="staff_num" name="staff_num" value="<%=staff_num%>" style="<%=input_text_gray%>">
		  	</td>	  
	  	</tr>

	  	<tr>
	  		<td style="<%=style1%>">用餐环境&nbsp;&nbsp;</td>
	  		<td >
		  		<input type="radio" id="position_room" onclick="onClickRadio_position('position_room')"><font style="font-size:12px; height:12px; margin-bottom:2px">包厢</font>
		  		<input type="radio" id="position_mall" onclick="onClickRadio_position('position_mall')"><font style="font-size:12px; height:12px; margin-bottom:2px">大厅</font>
		  		<input type="radio" id="position_any" onclick="onClickRadio_position('position_any')"><font style="font-size:12px; height:12px; margin-bottom:2px">不限</font>		  		
		  	</td>
	  		<td style="<%=style1%>">预订要求&nbsp;&nbsp;</td>
	  		<td>
		  		<input type="checkbox" id="window" name="window" /><font style="font-size:12px; height:12px; margin-bottom:2px">靠窗 </font>
		  		<input type="checkbox" id="nosmoking" name="nosmoking" /><font style="font-size:12px; height:12px; margin-bottom:2px">无烟区</font>
		  		<input type="checkbox" id="baby" name="baby" /><font style="font-size:12px; height:12px; margin-bottom:2px">宝宝椅</font>
		  		<input type="checkbox" id=wc name="wc" /><font style="font-size:12px; height:12px; margin-bottom:2px">卫生间</font>	  		
		  	</td>
		  	
		  	<td style="<%=style1%>">商旅卡号&nbsp;&nbsp;</td>
		  	<td>
		  		<input type="text" id="card_no" name="card_no" value="<%=card_no%>" readonly="readonly" style="<%=input_text_gray%>" >
		  	</td>  
		  	<!-- 
		  	<td style="<%=style1%>">确认方式&nbsp;&nbsp;</td>
	  		<td>
		  		<input type="checkbox" id="notice_phone" /><font style="font-size:12px; height:12px; margin-bottom:2px">电话 </font>
		  		<input type="checkbox" id="notice_sms" /><font style="font-size:12px; height:12px; margin-bottom:2px">短信</font>		
		  	</td>
		  	 -->		  	
	  	</tr>
	  	<tr>
	  		<td style="<%=style1%>">下单人&nbsp;&nbsp;</td>
	  		<td>
				<input type="text" id="create_manager_name" name="create_manager_name" value="<%=create_manager_name%>" readonly="readonly" style="<%=input_text_gray%>">
		  	</td>
		  	
		  	<td style="<%=style1%>">下单时间&nbsp;&nbsp;</td>
	  		<td>
				<input type="text" id="create_time_str" name="create_time_str" value="<%=create_time_str%>" readonly="readonly" style="<%=input_text_gray%>">
		  	</td>
		  	
		  	<td style="<%=style1%>">订单编号&nbsp;&nbsp;</td>
		  	<td>
		  		<input type="text" id="ticket_id" name="ticket_id" value="<%=ticket_id%>" readonly="readonly" style="<%=input_text_gray%>" >
		  	</td>		  	
	  	</tr>
	  	<tr>
	  		<td style="<%=style1%>">附加要求&nbsp;&nbsp;</td>
		  	<td colspan="1">
		  		<textarea id="demand_addition" name="demand_addition" style="<%=input_text_gray%>; height:80px" ><%=demand_addition%></textarea>
		  	</td>
		  	<!-- 	  	
		  	<td style="<%=style1%>">客户更改&nbsp;&nbsp;</td>
		  	<td colspan="1">
		  		<textarea rows="" cols="" id="custom_change" name="custom_change" readonly="readonly" style="<%=input_text_gray%>; height:80px"><%=custom_change%></textarea>
		  	</td>
		  	 -->	
		  	<td style="<%=style1%>">商家更改&nbsp;&nbsp;</td>
		  	<td>
		  		<input type="text" id="business_change" name="business_change" value="<%=business_change%>" readonly="readonly" style="<%=input_text_gray%>; height:80px">
		  	</td>	

	  	</tr>
	 
	 
	 
  		<tr>
  			<th colspan="6" align="left">&nbsp;确认信息</th>  		
  		</tr>
  		<tr>
  			<td style="<%=style1%>">预订结果&nbsp;&nbsp;</td>
  			<td>
  				<input type="text" id="business_response" name="business_response" value="<%=business_response%>" readonly="readonly" style="<%=input_text_gray%>" >
   			</td>
   			
   			<td style="<%=style1%>">折扣说明&nbsp;&nbsp;</td>
   			<td>
   				<input type="text" id="discount_descrip" name="discount_descrip" value="<%=discount_descrip%>" readonly="readonly" style="<%=input_text_gray%>" >
   			</td>
   			
   			<td style="<%=style1%>">备注&nbsp;&nbsp;</td>
   			<td>
   				<input type="text" id="comment_text" name="comment_text" value="<%=comment_text%>" readonly="readonly" style="<%=input_text_gray%>" >
   			</td>
  		</tr>
  		
  		<tr>
  			<td style="<%=style1%>">商家联系人&nbsp;&nbsp;</td>
  			 <td>
   				<input type="text" id="contact" name="contact" value="<%=contact%>" readonly="readonly" style="<%=input_text_gray%>" >
   			</td>
   			
   			<td style="<%=style1%>">要定金&nbsp;&nbsp;</td>
   			<td>
   				<input type="checkbox" id="check_deposit" />			
   			</td>
  		</tr>
  		
  		<tr>
  			<td style="<%=style1%>">选项&nbsp;&nbsp;</td>
  			 <td>
   				<input type="checkbox" id="auto_confirm" /><font style="font-size:12px; height:12px; margin-bottom:2px"><%=auto_confirm_tip%></font>				
   			</td>		
  
  		</tr>
  	
  	</table> 
  	
  	<br/>
  	<% if(mode.equals("----------------mode_edit-----------")) { //目前不需要了  先不让它显示 %> 	
	<input type="checkbox" id="checkbox_autolock" name="checkbox_autolock" checked="checked" onclick="onClick_AutoLock()"/><font style="color: gray;font-style: italic" >自动锁定</font>
	<%} %>
	<br/>
	
  	<table width="100%">
  		<tr><td align="center">
  		<input type="button" id="btn_confirm" value="" onclick="onConfirm()"  style="display: none">&nbsp;&nbsp;
		<input type="button" id="btn_confirm_failed" value="确认失败" onclick="onConfirmFailed()" style="display: none">&nbsp;&nbsp;
		<input type="button" id="btn_edit_save" value="保存修改" onclick="onEditSave()" style="display: none">
		<input type="button" id="btn_sms" value="发送短信" onclick="onSMS()" style="display: none">
		</td></tr>
  	</table>	
  	<form id="submitForm" method="post" action="ticket/editTicket.exec" style="display: none;">
  		<input id="OPERATE_TYPE" name="OPERATE_TYPE" value="" />
  		<input id="PARAM" name="PARAM" value="" />
  		<input id="final_callback" name="final_callback" value="<%=final_callback%>" />
  	</form>
  	
  	<SCRIPT LANGUAGE="JavaScript">
  		var auto_lock = ""; 
  		var from = "<%=from%>";
  		function onLoad() {  			
  			if("<%=bExist%>" == "0") {
  				alert("根据查到指定的订单");
  				return;
  			}
  			var cur_version = "<%=cur_version%>";
  			var version_str = "<%=version_str%>";
  			if(cur_version != version_str) {
  				alert("订单已经发生了变化，请先刷新");
  				return;
  			}
  			
  			resetControls();
  			enableControls();
  			
  			if("<%=mode%>" == "mode_confirm") {
  				document.getElementById("btn_confirm").style.display = "";  				
  				if(from == "1") {
  					document.getElementById("btn_confirm").value = "客户确认";
  				} else if(from == "2"){
  					document.getElementById("btn_confirm").value = "商家确认";
  				}
  				
  				document.getElementById("btn_confirm_failed").style.display = "";
  				document.getElementById("btn_sms").style.display = "";
  				
  				if("<%=auto_confirm_disabled%>" == "1") {
  					document.getElementById("auto_confirm").disabled = true;
  					document.getElementById("auto_confirm").checked = false;
  				} else {
  					document.getElementById("auto_confirm").disabled = false;
  					document.getElementById("auto_confirm").checked = true;
  				}
  			} else if("<%=mode%>" == "mode_edit") {
  				document.getElementById("btn_edit_save").value="保存客户修改";
  				document.getElementById("btn_edit_save").style.display = "";
  				
  				if("<%=auto_confirm_disabled%>" == "1") {
  					document.getElementById("auto_confirm").disabled = true; 
  				} else {
  					document.getElementById("auto_confirm").disabled = false;
  				}  				
  				document.getElementById("auto_confirm").checked = false; //编辑模式下，不自动确认
  			}
  			
  			var error = "<%=error%>";
  			if(error != null && error != "") {
  				alert(error);
  				window.close();
  			}
  		}  		
  		function resetControls() {  			
  			
  			document.getElementById("demand_time_d").disabled = true;
 			document.getElementById("demand_time_t").disabled = true;
 			
  			document.getElementById("demand_num").readOnly = true;
  			document.getElementById("demand_addition").readOnly = true;
  			document.getElementById("staff_num").readOnly = true;
  			document.getElementById("business_change").readOnly = true;
  			  			
  			document.getElementById("demand_num").style.background = "#C0C0C0";
  			document.getElementById("demand_addition").style.background = "#C0C0C0";
  			document.getElementById("staff_num").style.background = "#C0C0C0";
  			document.getElementById("business_change").style.background = "#C0C0C0";			
  			
  			if("<%=position_flag%>" == "0") {  			
  				document.getElementById("position_any").checked = true;
  			} else if("<%=position_flag%>" == "1") {
  				document.getElementById("position_mall").checked = true;
  			} else if("<%=position_flag%>" == "2") {
  				document.getElementById("position_room").checked = true;
  			}
  			document.getElementById("position_any").disabled = true;
  			document.getElementById("position_mall").disabled = true;
  			document.getElementById("position_room").disabled = true;	
  			
  			if("<%=window_flag%>" == "1") {
  				document.getElementById("window").checked = true;
  			}
  			if("<%=nosmoking_flag%>" == "1") {
  				document.getElementById("nosmoking").checked = true;
  			}
  			if("<%=baby_flag%>" == "1") {
  				document.getElementById("baby").checked = true;
  			}
  			if("<%=wc_flag%>" == "1") {
  				document.getElementById("wc").checked = true;
  			}
  			document.getElementById("window").disabled = true;
  			document.getElementById("nosmoking").disabled = true;
  			document.getElementById("baby").disabled = true;
  			document.getElementById("wc").disabled = true;
  			
  			/* //去掉确认方式
  			if("<%=notice_flag%>" == "1") {
  				document.getElementById("notice_phone").checked = true;
  			} else if("<%=notice_flag%>" == "2") {
  				document.getElementById("notice_sms").checked = true;
  			} else if("<%=notice_flag%>" == "3") {
  				document.getElementById("notice_phone").checked = true;
  				document.getElementById("notice_sms").checked = true;
  			}
  			document.getElementById("notice_phone").disabled = true;
  			document.getElementById("notice_sms").disabled = true;
  			*/

			if("<%=need_deposit%>" == "1") {
				document.getElementById("check_deposit").checked = true;
			}
			document.getElementById("check_deposit").disabled = true;
			
			

			document.getElementById("business_response").readOnly = true;
  			document.getElementById("discount_descrip").readOnly = true;
  			document.getElementById("comment_text").readOnly = true;
  			document.getElementById("contact").readOnly = true;
			document.getElementById("check_deposit").disabled = true;
			document.getElementById("business_response").style.background = "#C0C0C0";
			document.getElementById("discount_descrip").style.background = "#C0C0C0";
			document.getElementById("comment_text").style.background = "#C0C0C0";
			document.getElementById("contact").style.background = "#C0C0C0";

			var sex = "<%=cust_sex%>";
			if(sex == "1") {
				document.getElementById("sex_male").checked = true
			} else if(sex == "0") {
				document.getElementById("sex_female").checked = true
			} else {
				document.getElementById("sex_unknown").checked = true
			}
  		}
  		
  		function enableControls() {
  		
  			document.getElementById("cust_tel").readOnly = false;
  			document.getElementById("cust_tel").style.background = "#FFFFFF";
  			document.getElementById("cust_name").readOnly = false;
  			document.getElementById("cust_name").style.background = "#FFFFFF";
  			
  			document.getElementById("card_no").readOnly = false;
  			document.getElementById("card_no").style.background = "#FFFFFF";
  			  		 
  		  	document.getElementById("demand_time_d").disabled = false;
  			document.getElementById("demand_time_t").disabled = false;
  			
  			document.getElementById("demand_num").readOnly = false;
  			document.getElementById("demand_addition").readOnly = false;
  			document.getElementById("staff_num").readOnly = false;
  			
  			document.getElementById("demand_num").style.background = "#FFFFFF";
  			document.getElementById("demand_addition").style.background = "#FFFFFF";
  			document.getElementById("staff_num").style.background = "#FFFFFF";
  			
  			document.getElementById("position_any").disabled = false;
  			document.getElementById("position_mall").disabled = false;
  			document.getElementById("position_room").disabled = false;	
  			
  			document.getElementById("window").disabled = false;
  			document.getElementById("nosmoking").disabled = false;
  			document.getElementById("baby").disabled = false;
  			document.getElementById("wc").disabled = false;
  			
  			//document.getElementById("notice_phone").disabled = false;
  			//document.getElementById("notice_sms").disabled = false;
  			
  			//放开确认信息
  			document.getElementById("business_response").readOnly = false;
  			document.getElementById("discount_descrip").readOnly = false;
  			document.getElementById("comment_text").readOnly = false;
  			document.getElementById("contact").readOnly = false;
			document.getElementById("check_deposit").disabled = false;
			document.getElementById("business_response").style.background = "#FFFFFF";
			document.getElementById("discount_descrip").style.background = "#FFFFFF";
			document.getElementById("comment_text").style.background = "#FFFFFF";
			document.getElementById("contact").style.background = "#FFFFFF";
  		} 		
  		
  		function onConfirm() {
  		
  			if(generateParam() == true) {
	  			document.getElementById("OPERATE_TYPE").value = "CONFIRM";  				
				document.getElementById("submitForm").submit();
			}
  			
  		}
  		
  		function formatChangeTitle(title) {
  			return "[" + title + "]";
  		}
  		
  		function generateParam() {
   			var custom_change = "";
  			var flag = "更改为："
 			var nessesary = 0;
 			var optional = 0;

  			//预约时间
  			var new_demand_time = document.getElementById("demand_time_d").value;
  			if(IsEmpty(new_demand_time)==true) {
  	  			alert("请预约时间");
  	  			return false;
  			}  			 			
  			
  			var temp = document.getElementById("demand_time_t").value;
  			if(IsEmpty(temp)==true) {
  	  			alert("请预约时间");
  	  			return false;
  			}
  			new_demand_time += " ";
  			new_demand_time += temp;  			
  			if(new_demand_time != "<%=demand_time_str%>") {
  				custom_change += formatChangeTitle("预约时间");
  				custom_change += "<%=demand_time_str%>"; custom_change += "时"
  				custom_change += flag;
  				custom_change += new_demand_time; custom_change += "时"
  				custom_change += "\n";
  				
  				nessesary++;
  			}
  			
  			//预约桌数
  			var new_demand_num = document.getElementById("demand_num").value;
  			if(IsInteger(new_demand_num)==false) {
  	  			alert("请正确数据预约桌数，只能为数字");
  	  			return false;
  			}
  			if(new_demand_num != "<%=demand_num%>") {
  				custom_change += formatChangeTitle("预约桌数");
  				custom_change += "<%=demand_num%>";
  				custom_change += flag;
  				custom_change += new_demand_num;
  				custom_change += "\n";
  				
  				nessesary++;
  			}
  			
  			//用餐人数
  			var new_staff_num = document.getElementById("staff_num").value;
  			if(IsInteger(new_staff_num)==false) {
  	  			alert("请正确填写用餐人数");
  	  			return false;
  			}
  			if(new_staff_num != "<%=staff_num%>") {
  				custom_change += formatChangeTitle("用餐人数");
  				custom_change += "<%=staff_num%>";
  				custom_change += flag;
  				custom_change += new_staff_num;
  				custom_change += "\n";
  				  				
  				nessesary++;
  			}
  			
  			//附加条件 
  			/* 客户更改已经去掉了 屏蔽这个，否则如果有换行可能报错			 			
  			var new_demand_addition = document.getElementById("demand_addition").value;
  			if(new_demand_addition != "<%=demand_addition%>") {
  				custom_change += formatChangeTitle("附加要求");
  				custom_change += "<%=demand_addition%>";
  				custom_change += flag;
  				custom_change += new_demand_addition;
  				custom_change += "\n";
  				
  				nessesary++;
  			}
  			*/
  			
  			//就餐环境
  			var tip = "";
  			var new_position_flag = "";  			
  			if(document.getElementById("position_mall").checked == true) {
  				new_position_flag = "1";
  				tip = "大厅";
  			} else if(document.getElementById("position_room").checked == true) {
  				new_position_flag = "2";
  				tip = "包房";
  			} else if(document.getElementById("position_any").checked == true) {
  				new_position_flag = "0";
  				tip = "不限";
  			}
  			if(new_position_flag != "<%=position_flag%>") {
  				custom_change += formatChangeTitle("用餐环境");
  				custom_change += "<%=position_tip%>";
  				custom_change += flag;
  				custom_change += tip;
  				custom_change += "\n";
  				
  				nessesary++;
  			}
  			
  			//
  			var new_window_flag = "";
  			if(document.getElementById("window").checked == true) {
  				new_window_flag = "1";
  			}
  			if(new_window_flag == "1" && new_window_flag != "<%=window_flag%>") { //旧值不是1
  			  	custom_change += formatChangeTitle("要求靠窗");
  			  	custom_change += "\n";  				
  				nessesary++;
  			}
  			
  			var new_nosmoking_flag = "";
  			if(document.getElementById("nosmoking").checked == true) {
  				new_nosmoking_flag = "1";
  			}
  			if(new_nosmoking_flag == "1" && new_nosmoking_flag != "<%=nosmoking_flag%>") { //旧值不是1
  			  	custom_change += formatChangeTitle("要求无烟区");
  			  	custom_change += "\n";  				
  				nessesary++;
  			}
  			
  			var new_baby_flag = "";
  			if(document.getElementById("baby").checked == true) {
  				new_baby_flag = "1";
  			}
  			if(new_baby_flag == "1" && new_baby_flag != "<%=baby_flag%>") { //旧值不是1
  			  	custom_change += formatChangeTitle("要求宝宝椅");
  			  	custom_change += "\n";  				
  				nessesary++;
  			}
  			
  			var new_wc_flag = "";
  			if(document.getElementById("wc").checked == true) {
  				new_wc_flag = "1";
  			}
  			if(new_wc_flag == "1" && new_wc_flag != "<%=wc_flag%>") { //旧值不是1
  			  	custom_change += formatChangeTitle("要求带卫生间");
  			  	custom_change += "\n";  				
  				nessesary++;
  			}

			//if(nessesary == 0) {
			//	alert("订单未发生更改");
			//	return;
			//}
  			
  			var new_card_no = document.getElementById("card_no").value;
  			
  			var new_notice_flag = 0;
  			/* //去掉确认方式 
  			if(document.getElementById("notice_phone").checked == true &&
  				document.getElementById("notice_sms").checked == true) {
  				new_notice_flag = 3;
  			} else if(document.getElementById("notice_phone").checked == true) {
  				new_notice_flag = 1;
  			} else if(document.getElementById("notice_sms").checked == true) {
  				new_notice_flag = 2;
  			} else {
  				alert("请选择通知方式");
  				return false;
  			}
  			*/
  			
  			custom_change = ""; //不要客户更改，永远给他空
  			
  			var param = "{TICKET_ID:";
  			param += "'"+"<%=ticket_id%>"+"',";
  			param += "BUSINESS_ID:";
  			param += "'"+document.getElementById("business_id").value+"',";  			
  			param += "MYVERSION:";
  			param += "'"+"<%=version_str%>"+"',";
  			param += "DEMAND_TIME:";
  			param += "'"+new_demand_time+"',";
  			param += "DEMAND_NUM:";
  			param += "'"+new_demand_num+"',";
  			param += "DEMAND_ADDITION:";
  			param += "'"+document.getElementById("demand_addition").value+"',";
  			param += "STAFF_NUM:";
  			param += "'"+new_staff_num+"',";
  			param += "POSITION_FLAG:";
  			param += "'"+new_position_flag+"',";
  			param += "WINDOW_FLAG:";
  			param += "'"+new_window_flag+"',";
  			param += "BABY_FLAG:";
  			param += "'"+new_baby_flag+"',";
  			param += "NOSMOKING_FLAG:";
  			param += "'"+new_nosmoking_flag+"',";
  			param += "WC_FLAG:";
  			param += "'"+new_wc_flag+"',";
  			
  			param += "CUSTOM_CHANGE:";  //确认模式不需要(后台未使用)
  			param += "'"+custom_change+"',";
  			
  			param += "CARD_NO:";
  			param += "'"+new_card_no+"',";
  			
  			param += "NOTICE_FLAG:";
  			param += "'"+new_notice_flag+"',";
  			
  			param += "CUST_TEL:";
  			param += "'"+document.getElementById("cust_tel").value+"',";
  			param += "CUST_NAME:";
  			param += "'"+document.getElementById("cust_name").value+"',"; 
  			
  			//性别
  			var cust_sex = "-1";
  			if(document.getElementById("sex_male").checked == true) {
  				cust_sex = "1";
  			} else if(document.getElementById("sex_female").checked == true) {
  				cust_sex = "0";
  			} else {
  				cust_sex = "-1";
  			}
  			param += "CUST_SEX:";
  			param += "'"+cust_sex+"',"; 
  			
  			//确认信息
  			var tmp = "0";
  			if(document.getElementById("check_deposit").checked == true) {
  				tmp = "1";
  			}
  			param += "BUSINESS_RESPONSE:";
  			param += "'"+document.getElementById("business_response").value+"',";
  			param += "DISCOUNT_DESCRIP:";
  			param += "'"+document.getElementById("discount_descrip").value+"',";
  			param += "COMMENT_TEXT:";
  			param += "'"+document.getElementById("comment_text").value+"',";
  			param += "CONTACT:";
  			param += "'"+document.getElementById("contact").value+"',";
  			param += "NEED_DEPOSIT:";
  			param += "'"+tmp+"',";
  			
  			param += "__AUTO_LOCK:"; //确认模式不需要(后台未使用)
  			param += "'"+auto_lock+"',";
  			
  			var auto_confirm="0";
  			if(document.getElementById("auto_confirm").checked == true) {
  				auto_confirm = "1";
  			}
  			param += "AUTO_CONFIRM:";
  			param += "'"+auto_confirm+"',";
  			
			param += "FROM:";
  			param += "'"+from+"'";
  			
  			param += "}";
  			
  			//提交  			
  			document.getElementById("PARAM").value = param;			
  			return true;
  			
  	  		//在网页对话框中ajax有问题 	  			
//			$.ajax({
//				type: "POST",
//				url: "ticket/editTicket.ajax",
//				data: {OPERATE_TYPE:"EDIT", PARAM:param},
//				datatype:"json",
//				success: editSuccess,
//				error: show_error
//  	  		});
  		}  		
  		function editSuccess(data) {
  			alert(data);
  			window.close();
  		}
 		function showMsg(data) {
  	  		alert(data);
 		}  		
  		function onConfirmFailed() {
  			//目前使用change_from撤单发起方
  			if("<%=mode%>" == "mode_confirm") { //仅审核模式
  				var tip = "确认是";
  				if(from == "1") {
  					tip += "客户";
  				} else if(from == "2") {
  					tip += "商家";
  				} else {
  					return; 
  				}
  				tip += "确认失败吗？"
  				if(window.confirm(tip) == false) return;
  				
	  			var param = "{TICKET_ID:";
	  			param += "'"+"<%=ticket_id%>"+"',";
	  			param += "FAILED_FROM:";
	  			param += "'"+from+"',";
	  			param += "MYVERSION:";
	  			param += "'"+"<%=version_str%>"+"'";	  			  			
	  			param += "}"; 
	  			
	  			document.getElementById("OPERATE_TYPE").value = "CONFIRMFAILED";
	  			document.getElementById("PARAM").value = param;
	  			document.getElementById("submitForm").submit();		 				
  	  		} //end if			
  		}
  		
  		function onClickRadio_position(id) {
  			if(id == 'position_room') {
 				document.getElementById("position_room").checked = true;
 				document.getElementById("position_mall").checked = false;
 				document.getElementById("position_any").checked = false;
 			} else if(id == 'position_mall'){
 				document.getElementById("position_mall").checked = true;
 				document.getElementById("position_room").checked = false;
 				document.getElementById("position_any").checked = false;
 			} else {
 				document.getElementById("position_any").checked = true;
 				document.getElementById("position_mall").checked = false;
 				document.getElementById("position_room").checked = false;
 			}
  		}
  		
  		function onClick_AutoLock() {
  		  	if(document.getElementById("checkbox_autolock").checked == true) {
  				auto_lock = "1";
  			} else {
  				auto_lock = "";
  			} 
  		}
  		
  		function onEditSave(){
  			if(generateParam() == true) {
  				if("<%=lock_manager%>" != "") {
  					var tip = "所选的订单当前被"+"<%=lock_manager_name%>"+"锁定，确认要保存修改吗?"
  					if(window.confirm(tip) == false) return;
  				}
  				
	  			document.getElementById("OPERATE_TYPE").value = "EDIT";  				
				document.getElementById("submitForm").submit();
			}
  		}
  		
  		function OnChangeBusiness() {
  			var url = "<%=path%>";
  			url += "/page/queryBusinessForTicket.jsp;"
  			var param = "status:no;scroll:yes;dialogWidth:1024px;dialogHeight:600px";
			window.showModelessDialog(url, window, param); 
  		}
  		
  		function onClickRadio_sex(id) {
  			var postfix = "";
  			if(id == 'sex_male') {
 				document.getElementById("sex_male").checked = true;
 				document.getElementById("sex_female").checked = false;
 				document.getElementById("sex_unknown").checked = false;
 				
 				postfix = "先生";
 			} else if(id == 'sex_female'){
 				document.getElementById("sex_female").checked = true;
 				document.getElementById("sex_male").checked = false; 				
 				document.getElementById("sex_unknown").checked = false;
 				
 				postfix = "女士";
 			} else {
 				document.getElementById("sex_unknown").checked = true;
 				document.getElementById("sex_female").checked = false;
 				document.getElementById("sex_male").checked = false; 				
 			}
 			
 			var name = document.getElementById("cust_name").value;
 			var index = name.indexOf("先生");
 			if(index == -1) index = name.indexOf("女士");
 			if(index > -1 && name.length-2 == index) {
 				//存在"先生" 或 "女士"， 并且是在最后
 				name = name.substr(0,index);
 			}
 			document.getElementById("cust_name").value = name+postfix; 	
  		}
  		
  		function onSMS() { 			
 			var url = "<%=path%>";
 			var ticket_id = "<%=ticket_id%>";
 			var tel = "<%=cust_tel%>";
  			url += "/page/ticketSMS.jsp?ticket_id=" + ticket_id;
  			url += "&telno=" + tel;
  			url += "&type=1"; //默认是1 预定成功
  			
  			var width = 460; //弹出窗口的宽度;
			var height = 320; //弹出窗口的高度;
			var top = (window.screen.availHeight-30-height)/2; //获得窗口的垂直位置;
			var left = (window.screen.availWidth-10-width)/2; //获得窗口的水平位置;
			var style = "toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no";			
			window.open (url,"短信","height="+height+",width="+width+",top="+top+",left="+left+","+style); 			
 		}
  	</SCRIPT>
	</body>
</html>
